package com.veeder.datacollection.rs232.response.handler;

import com.veeder.datacollection.exception.SyntaxException;
import com.veeder.datacollection.rs232.response.TankResponseReport;
import com.veeder.datacollection.util.DataUtil;
import com.veeder.datacollection.util.DateUtil;

public class RS606RspHandler extends CmdRspParser{

	@Override
	public TankResponseReport<Float[]> parseCoreResponse(String coreResponse) throws SyntaxException {
		TankResponseReport<Float[]> result = null;
		try {
			result =new TankResponseReport<Float[]>();
			int position = 6;
			result.setTlsSysDate(
					DateUtil.convertToDate(coreResponse.substring(position, position += 10), DateUtil.DateFormat1));
			while (position < coreResponse.length()) {
				int tankId = Integer.parseInt(coreResponse.substring(position, position += 2));
				
				final int pointsCount= 20;
				Float[] volumesArray= new Float[pointsCount];
				for(int i=0;i<pointsCount;i++){
					float volume= DataUtil.hexToFloat(coreResponse.substring(position, position += 8));
					volumesArray[i]=volume;
				}
				result.setTankReponse(tankId, volumesArray);
			}
		} catch (Exception e) {
			throw new SyntaxException(e.toString());
		}

		return result;
	}
	
	
//	public static void main(String[] args) {
//		String response = "i606" + "02"
//				+ "16122002300246F9D60000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000&&DDB6";
//
//		RS606RspHandler handler = new RS606RspHandler();
//		try {
//			RS232Response response2 = handler.parseResponse(response);
//			if (response2 instanceof TankResponseReport) {
//				TankResponseReport<Float[]> chart = (TankResponseReport<Float[]>) response2;
//				Float[] array= chart.getResponse(2);
//				for(Float i: array){
//					System.out.println(i);
//				}
//			}
//		} catch (SyntaxException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//
//}
	
 
}